package cn.ac.jaas.isc.vegetable.pbms.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.ac.jaas.isc.vegetable.common.core.util.R;
import cn.ac.jaas.isc.vegetable.common.log.annotation.SysLog;
import cn.ac.jaas.isc.vegetable.pbms.api.entity.ArcDeviceType;
import cn.ac.jaas.isc.vegetable.pbms.service.ArcDeviceTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import cn.ac.jaas.isc.vegetable.common.excel.annotation.ResponseExcel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 装置类型表
 *
 * @author 张高昌
 * @date 2022-05-21 18:03:32
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/arcdevicetype")
@Api(value = "arcdevicetype", tags = "装置类型表管理")
public class ArcDeviceTypeController {

    private final ArcDeviceTypeService arcDeviceTypeService;

    /**
     * 分页查询
     *
     * @param page          分页对象
     * @param arcDeviceType 装置类型表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('pbms_arcdevicetype_view')")
    public R getArcDeviceTypePage(Page page, ArcDeviceType arcDeviceType) {
        return R.ok(arcDeviceTypeService.page(page, Wrappers.query(arcDeviceType)));
    }


    /**
     * 通过id查询装置类型表
     *
     * @param deviceTypeId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{deviceTypeId}")
    @PreAuthorize("@pms.hasPermission('pbms_arcdevicetype_view')")
    public R getById(@PathVariable("deviceTypeId") Integer deviceTypeId) {
        return R.ok(arcDeviceTypeService.getById(deviceTypeId));
    }

    /**
     * 新增装置类型表
     *
     * @param arcDeviceType 装置类型表
     * @return R
     */
    @ApiOperation(value = "新增装置类型表", notes = "新增装置类型表")
    @SysLog("新增装置类型表")
    @PostMapping
    @PreAuthorize("@pms.hasPermission('pbms_arcdevicetype_add')")
    public R save(@RequestBody ArcDeviceType arcDeviceType) {
        return arcDeviceTypeService.saveDeviceType(arcDeviceType);
    }

    /**
     * 修改装置类型表
     *
     * @param arcDeviceType 装置类型表
     * @return R
     */
    @ApiOperation(value = "修改装置类型表", notes = "修改装置类型表")
    @SysLog("修改装置类型表")
    @PutMapping
    @PreAuthorize("@pms.hasPermission('pbms_arcdevicetype_edit')")
    public R updateById(@RequestBody ArcDeviceType arcDeviceType) {
        return arcDeviceTypeService.updateDeviceTypeById(arcDeviceType);
    }

    /**
     * 通过id删除装置类型表
     *
     * @param deviceTypeId id
     * @return R
     */
    @ApiOperation(value = "通过id删除装置类型表", notes = "通过id删除装置类型表")
    @SysLog("通过id删除装置类型表")
    @DeleteMapping("/{deviceTypeId}")
    @PreAuthorize("@pms.hasPermission('pbms_arcdevicetype_del')")
    public R removeById(@PathVariable Integer deviceTypeId) {
        return R.ok(arcDeviceTypeService.removeById(deviceTypeId));
    }


    /**
     * 导出excel 表格
     *
     * @param arcDeviceType 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('pbms_arcdevicetype_export')")
    public List<ArcDeviceType> export(ArcDeviceType arcDeviceType) {
        return arcDeviceTypeService.list(Wrappers.query(arcDeviceType));
    }

    /**
     * 通过设备编码获取装置类型
     *
     * @param equipmentCode 设备编码
     * @return
     */
    @ApiOperation(value = "通过设备编码获取装置类型", notes = "通过设备编码获取装置类型")
    @GetMapping("/getDeviceTypeAll/{equipmentCode}")
    @PreAuthorize("@pms.hasPermission('pbms_arcdevicetype_view')")
    public R getDeviceTypeAll(@PathVariable("equipmentCode") String equipmentCode) {

        return R.ok(arcDeviceTypeService.getDeviceTypeAll(equipmentCode));
    }
}
